package com.yinhai.message.manage.msgmg.controller;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.yinhai.core.app.api.util.JSonFactory;
import com.yinhai.core.app.ta3.web.controller.BaseController;
import com.yinhai.core.common.api.base.IPage;
import com.yinhai.core.common.ta3.dto.TaParamDto;
import com.yinhai.message.manage.msgmg.bpo.IMessageMgBpo;
import com.yinhai.message.manage.msgmg.vo.MessageDetailVo;
import com.yinhai.message.manage.msgmg.vo.MessageFileVo;
import com.yinhai.message.manage.msgmg.vo.MessageVo;
import com.yinhai.message.manage.sysapp.bpo.ISysAppBpo;

/**
 * @author aolei 2017年3月28日16:48:45
 *         <p>
 *         消息管理controllter
 */
@RequestMapping("messageMg")
@Controller
public class MessageMgController extends BaseController {

    @Resource
    private IMessageMgBpo messageMgBpo;

    @Resource
    private ISysAppBpo sysAppBpo;


    /**
     * aolei 2017年3月28日16:50:05
     * 进入消息管理页面方法，
     * <p>
     * URL:messageMg/messageMgController.do
     *
     * @return
     */
    @RequestMapping("messageMgController.do")
    public String execute(HttpServletRequest request) {
       request.setAttribute("syspath", JSonFactory.bean2json(sysAppBpo.getSysAppList()));
       request.setAttribute("users", JSonFactory.bean2json(messageMgBpo.getAlllUserInfo()));
        return "/manage/msgmg/messageMg";
    }

    /**
     * aolei 2017年3月28日17:09:13
     * 进入消息详细信息查看页面，
     * <p>
     * URL:messageMg/messageMgController!toShowMessageDetail.do
     */
    @RequestMapping("messageMgController!toShowMessageDetail.do")
    public String toShowMessageDetail(HttpServletRequest request) {
        TaParamDto paramDto = getTaDto();
        String messageId = paramDto.getAsString("messageid");
        String content = messageMgBpo.queryMessageContextByMessageId(messageId);
        request.setAttribute("context", content);
        return "/manage/msgmg/messageMgDetail";
    }
    /**
     * aolei 2017年3月28日17:09:13
     * 查询消息附件
     * <p>
     * URL:messageMg/messageMgController!toShowMessageDetail.do
     */
    @RequestMapping("messageMgController!toShowFilesMessages.do")
    public String toShowFilesMessages(HttpServletRequest request) {
        TaParamDto paramDto = getTaDto();
        String messageId = paramDto.getAsString("messageid");
        List<MessageFileVo> fileList = messageMgBpo.queryMessageFilesByMessageId(messageId);
        request.setAttribute("file", fileList);
        return "/manage/msgmg/messageMgFiles";
    }


    /**
     * aolei 2017年3月28日20:42:18
     * 获取总消息信息
     * <p>
     * URL:messageMgController!showTotalMessages.do
     */
    @RequestMapping("messageMgController!showTotalMessages.do")
    public String showTotalMessages() {
        TaParamDto paramDto = getTaDto();
        String sendUserId = paramDto.getAsString("sendUserId");//TODO发送者userid
        String sendSyspath = paramDto.getAsString("senderSysId");
        String title = paramDto.getAsString("title");
        Date startTime = paramDto.getAsTimestamp("startTime");
        Date endTime = paramDto.getAsTimestamp("endTime");
        int start = paramDto.getStart("messageTotal");
        int limit = paramDto.getLimit("messageTotal");
        IPage<MessageVo> messageTotal = messageMgBpo.queryMessagesByParam(sendUserId, sendSyspath, title, startTime, endTime,
                start, limit, "messageTotal");
        setList("messageTotal", messageTotal);
        return JSON;
    }


    /**
     * aolei 2017年3月28日20:42:18
     * 点击某一条消息 获取 明细消息信息
     * <p>
     * URL:messageMgController!showDetailMessages.do
     */
    @RequestMapping("messageMgController!showDetailMessages.do")
    public String showDetailMessages() {
        TaParamDto paramDto = getTaDto();

        IPage<MessageDetailVo> messageTotal = messageMgBpo.queryMessageDetailsByMsgId(paramDto.getAsString("messageid"),
                paramDto.getStart("messageDetail"), paramDto.getLimit("messageDetail"), "messageTotal");
        setList("messageDetail", messageTotal);
        return JSON;
    }

}
